package com.hd123.rumba.gwt.widget.client.grid;

import com.hd123.rumba.gwt.widget.client.TextButtonBox;

public class StringButtonEditor extends TextButtonBox implements CellEditor {

  public void activate(DxGrid grid, int row, int col, String text, String width, String height,
      boolean readOnly) {
    super.setText(text);
    grid.setWidget(row, col, this);
    super.setReadOnly(readOnly);
    super.setWidth(width);
    super.setHeight("97%");
    super.setFocus(true);
  }

  public boolean isLeftKeyToLeave() {
    return isReadOnly() || getCursorPos() == 0;
  }

  public boolean isRightKeyToLeave() {
    return isReadOnly() || getText() == null || getCursorPos() == getText().trim().length();
  }

  public String getValue() {
    return getText();
  }

  public void setValue(String value) {
    setText(value);
  }
}
